import request from "@/utils/request";
import { rootsUrl } from "../utils";
import { getToken } from "@/utils/auth";
import Qs from "qs";

// 获取特展列表
export const getSpecExhibList = (pageIndex, type, title, year) => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpo/listSpexpo.shtml`,
    method: "get",
    params: {
      pageSize: 5,
      type,
      pageIndex,
      title,
      year
    }
  });
};

// 获取特展详情
export const getDetail = id => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpo/getSpexpoById.shtml`,
    method: "get",
    params: {
      id
    }
  });
};

// 获取展品分类类目
export const getClass = id => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpoType/listTypeBySpexpoId.shtml`,
    method: "get",
    params: {
      id
    }
  });
};

// 获取每个类型的展品
export const getDisplayItem = typeId => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpoSec/listSpexpoSecByTypeId.shtml`,
    method: "get",
    params: {
      typeId
    }
  });
};

// 获取展厅内景
export const getInnerScene = groupFileId => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpo/listInterior.shtml`,
    method: "get",
    params: {
      groupFileId
    }
  });
};

/**
 * 获取展品明细
 */
export const getItemDetail = id => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpoSec/getSpexpoSecById.shtml`,
    method: "get",
    params: {
      id
    }
  });
};

/**
 * 获取特展回顾有效年份
 */
export const getYears = () => {
  return request({
    url: `${rootsUrl[0]}/museum/spexpo/listSpexpoYear.shtml`,
    method: "get"
  });
};

// --------------------------- 展览众筹相关接口 start ----------------------------
/**
 * 获取展览众筹列表
 * @param {number} pageIndex
 * @param {number} pageSize
 */
export const getActList = (pageIndex, pageSize) => {
  return request({
    url: `${rootsUrl[0]}/museum/act/getActList.shtml`,
    method: "get",
    params: {
      pageIndex,
      pageSize: pageSize || 10,
      source: "web"
    }
  });
};

/**
 * 众筹活动——获某个众筹该活动详情
 * @param {Number} id
 */
export const getActDetail = id => {
  return request({
    url: `${rootsUrl[0]}/museum/act/getActDetails.shtml`,
    method: "get",
    params: {
      id
    }
  });
};

/**
 * 众筹活动--获取创意征集活动的作品列表
 */
export const getArtList = (id, userId) => {
  return request({
    url: `${rootsUrl[0]}/museum/design/getDesignList.shtml`,
    method: "get",
    params: {
      mid: userId,
      aid: id
    }
  });
};

/**
 * 获取创意征集活动作品详情
 * @param {Number} id 作品ID
 * @param {Number} userId 用户登录名  userId
 */
export const getArtDetail = (id, userId) => {
  let token = getToken();
  return request({
    url: `${rootsUrl[0]}/museum/design/getDesignDetails.shtml`,
    method: "get",
    params: {
      id,
      mid: userId,
      token
    }
  });
};

/**
 * 获取创意征集活动作品评论列表
 * @param {Number} id
 */
export const getArtCommentList = id => {
  let token = getToken();
  return request({
    url: `${rootsUrl[0]}/museum/design/getCommentList.shtml`,
    method: "get",
    params: {
      pageSize: 10000,
      token,
      id,
      type: 1
    }
  });
};

/**
 * 发表针对作品的评论
 * @param {Number} id 作品ID
 * @param {*} userId 当前用户登录ID
 * @param {*} content 评论内容
 */
export const postArtComment = (id, userId, content) => {
  let token = getToken();
  let data = {
    vid: id,
    mid: userId,
    content,
    type: 1,
    token
  };
  return request({
    url: `${rootsUrl[0]}/museum/design/addComment.shtml`,
    method: "post",
    headers: {
      "Content-type": "application/x-www-form-urlencoded"
    },
    data: Qs.stringify(data)
  });
};

/**
 * 上传我的作品
 */
export const postMyArt = (id, art) => {
  let token = getToken();
  let data = {
    aid: id,
    title: art.title,
    content: art.content,
    picture: art.picture,
    pictures: art.pictures,
    token
  };
  return request({
    url: `${rootsUrl[0]}/museum/design/saveDesign.shtml`,
    method: "post",
    headers: {
      "Content-type": "application/x-www-form-urlencoded"
    },
    data: Qs.stringify(data)
  });
};

/**
 * 为作品点赞
 * @param {Number} id 作品ID
 * @param {Number} userId 用户登录名
 */
export const likeArt = (id, userId) => {
  let token = getToken();
  return request({
    url: `${rootsUrl[0]}/museum/design/addLikes.shtml`,
    method: "get",
    params: {
      vid: id,
      mid: userId,
      token
    }
  });
};
